#ifndef CDYNLIB_H
#define CDYNLIB_H

#include <stdio.h>
#include <iostream>
#include <Windows.h>
#include "IPlugin.h"

#    define DYNLIB_HANDLE hInstance
#    define DYNLIB_LOAD( a ) LoadLibraryExA( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
#    define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
#    define DYNLIB_UNLOAD( a ) FreeLibrary( a )

struct HINSTANCE__;
typedef struct HINSTANCE__* hInstance;

class CDynLib
{

public:
    CDynLib(const std::string& strName)
    {
        mbMain = false;
        mstrName = strName;
#ifdef _DEBUG
        mstrName.append("_d");
#endif
        mstrName.append(".dll");

        printf("LoadPlugin:%s\n", mstrName.c_str());
    }

    ~CDynLib()
    {

    }

    IPlugin* Load();

    bool UnLoad();

    /// Get the name of the library
    const std::string& GetName(void) const
    {
        return mstrName;
    }

    const bool GetMain(void) const
    {
        return mbMain;
    }

    void* GetSymbol(const char* szProcName);

protected:

    std::string mstrName;
    bool mbMain;

    DYNLIB_HANDLE mInst;
};

#endif
